<template>
  <div class="login-page">
    <el-tabs type="border-card"  class="tabs">
      <el-tab-pane label="登录" class="tab-pane">
        <el-form :model="form" label-width="50px">
          <el-form-item label="账号">
            <el-input v-model="form.name"/>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="form.pwd" show-password/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="login">登录</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="注册" class="tab-pane">
        <el-form :model="form" label-width="50px">
          <el-form-item label="账号">
            <el-input v-model="form.name"/>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="form.pwd" show-password/>
          </el-form-item>
          <el-form-item label="电话">
            <el-input v-model="form.phone"/>
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input v-model="form.email"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="register">注册</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
    </el-tabs>

  </div>

</template>

<script>
import request from "@/axios/request.js";
import {ElMessage} from "element-plus";
import {base64DataToImgURL} from "@/utils/Base64Util.js";
export default {
  data() {
    return {
      form: {
        name: null,
        pwd: null,
        phone: null,
        email: null,
      },
      rules: {},
      img_url: null

    }
  },
  methods: {
    login() {
      request.post('/login', this.form).then((res) => {
        if (res.code === 200) {
          ElMessage({
            type: 'success',
            message: '登录成功!'
          })
          // 登陆成功后跳转到主页面
          // window.location.href = '/'

        } else {
          ElMessage({
            type: 'error',
            message: res.msg
          })
        }
      })
    },
    register() {
      request.post('/register', this.form).then((res) => {
        if (res.code === 200) {
          ElMessage({
            type: 'success',
            message: '注册成功!'
          })
        } else {
          ElMessage({
            type: 'error',
            message: res.msg
          })
        }
      })
    }
  },
}
</script>

<style scoped>
.login-page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  background-color: #222;
  color: white;
}



input {
  width: 100%;
  padding: 10px;
  border: 1px solid #555;
  background: #444;
  color: white;
  border-radius: 4px;
}

button {
  width: 100%;
  padding: 10px;
  background: #555;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background: #666;
}

.tabs {
  border-radius: 10px;  /*圆角*/
  width: 400px;
  margin: auto;
  display: flex;
  justify-content: center;
  background-color: #222222;
}
.tab-pane {
  background-color: #222222;
}
:deep(.el-tabs__header) {
  border-radius: 10px;  /*圆角*/
}
:deep(.el-tabs__nav-scroll) {
  border-radius: 10px;
  background-color: #3b3b3b;
}
</style>
